/*
 * UserManageAlert.fx
 *
 * Created on 2009-9-19, 21:57:50
 */

package com.sjtu.fx.tools;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import com.sjtu.fx.admin.UserManagement;

import com.sjtu.fx.admin.UserManagement.User;
/**
 * @author Yu Min-ting
 */

public class UserManageAlert extends CustomNode{
    public var bm:UserManagement;
    public var userId:String = "";
    public var userScore:String = "";
    public var users:User[];
    public var selection:Integer = -1;
    public var title= "Error";
    public var width = 250;
    public var height = 120;
    public var content = "Something Wrong!";
    public var click = false;
    public var confirm = false on replace{
        if(confirm){
            confirm = true;
        }else confirm = false;
    }


    var icon = ImageView {
        image: Image {
            url: "{__DIR__}icon.png"
        }
        fitWidth: 40
        preserveRatio: true
        smooth: true
        cache: true
        x:15 y:35
        opacity:0.9
    }

    var info = Text {
        font: Font {size:10 name: "Verdana"}
        fill: Color.rgb(11,51,60)
        content: bind content
        x:60 y:55
    };

     var t = Text{
                     content: bind title
                     x: 15 y: 20
                     fill: Color.rgb(11,51,60)
                     font: Font{ size:14 name: "Verdana Bold"}
    }

    var rec = Rectangle {
               width: 20, height: 20
               arcWidth: 5  arcHeight: 5
               fill: Color.rgb(152, 190, 198)
   }
   var close = Group{
       translateX:width-30 translateY:5
       content:[
          rec,
          Line {
              startX: 5
              startY: 5
              endX: 15
              endY: 15
              stroke: Color.WHITE
              strokeWidth: 2},
          Line {
              startX: 5
              startY: 15
              endX: 15
              endY: 5
              stroke: Color.WHITE
              strokeWidth: 2},
       ]
       opacity: 0.8
       onMouseEntered: function( e: MouseEvent ):Void {
           rec.fill = Color.RED;
       }
       onMouseExited: function( e: MouseEvent ):Void {
           rec.fill = Color.rgb(152, 190, 198);
       }
       onMouseClicked: function( e: MouseEvent ):Void {
            visible = false;
       }
   }//Group

  var yes = Button {
           text: "Yes"
           action: function() {
               //click = true;
               bm.setUserScore(userId, userScore, "reject");
               delete users[selection];
               confirm = true;
               visible = false;
           }
           translateX: width/2 -45
           translateY: height - 45
       }
  var no = Button {
           text: "No"
           action: function() {
               //click = true;
               confirm = false;
               visible = false;
           }
           translateX: width/2 + 15
           translateY: height - 45
       }

       var panel = Panel {
                    width:  bind  width
                    height: bind  height
                    title:  ""
                    translateX: 0
                    translateY: 0
       }

    override protected function create() : Node {

        Group{
            content:[
                panel,t,
                icon,info,close,yes,no


            ]

      }
    }



}
